package vn.edu.hut.soict.lsom.align;

import java.util.Map;
import java.util.Properties;

import org.semanticweb.owl.align.Alignment;
import org.semanticweb.owl.align.AlignmentException;
import org.semanticweb.owl.align.AlignmentProcess;

import fr.inrialpes.exmo.align.impl.ObjectAlignment;
import fr.inrialpes.exmo.ontowrap.Ontology;

public class CMAlignment extends ObjectAlignment implements AlignmentProcess{

	@Override
	public void align(Alignment alignment, Properties param)
			throws AlignmentException {
		// TODO Auto-generated method stub
		Map<String,String> human2UMLS = (Map)param.get("human2UMLS");
		Map<String,String> mouse2UMLS = (Map)param.get("mouse2UMLS");
		long start = System.currentTimeMillis();
		try {
			int counter = 0;
			int n = ontology2().getClasses().size()*ontology1().getClasses().size();
		    // Match classes
		    for ( Object cl2: ontology2().getClasses() ){
		    	for ( Object cl1: ontology1().getClasses() ){
				    // add mapping into alignment object 
		    		counter++;
		    		String mouseID = ontology1().getEntityName(cl1);
		    		String humanID = ontology2().getEntityName(cl2);
		    		
		    		String umlsHuman = human2UMLS.get(humanID);
		    		String umlsMouse = mouse2UMLS.get(mouseID);
		    		if (umlsHuman!=null && umlsMouse!=null){
			    		if (umlsHuman.compareToIgnoreCase(umlsMouse)==0){
			    			addAlignCell(cl1,cl2,"=",1.0);
			    			
			    		}
		    		}
		    		if (counter%800000 == 0){
		    			//System.out.print("\b\b\b\b\b");
		    			System.out.println();
		    			System.out.print(""+(counter*100/n)+"%");
		    			
		    		}
		    	}
		    	
		    }
		    long end = System.currentTimeMillis();
		    System.out.println();
		    System.out.println("Compose time: " + (end-start) +"ms");
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

}
